//
//  ImageScrollView.swift
//  TrafficViolation
//
//  Created by eaglelive on 2017/4/7.
//  Copyright © 2017年 eaglelive. All rights reserved.
//

import UIKit
import SDCycleScrollView

//banner滚动图片
class ImageScrollView: UIView {
    
    var cycleView = SDCycleScrollView()
    
    override init(frame: CGRect){
        
        super.init(frame: frame)
        
        cycleView = SDCycleScrollView.init(frame: .init(x: 0, y: 0, width: kScreenW, height: 150), delegate: self, placeholderImage: UIImage.init(named: ""))
        cycleView.autoScrollTimeInterval = 2;
        cycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight
        self.addSubview(cycleView)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // 设置图片
    func setScrollImage(imageArray: Array<ImageScrollModel>) {
        var urls = Array<String>()
        var titles = Array<String>()
        for model: ImageScrollModel in imageArray {
            urls.append(model.pic_url)
            titles.append(model.title)
        }
        cycleView.imageURLStringsGroup = urls
        cycleView.titlesGroup = titles
    }
}
extension ImageScrollView : SDCycleScrollViewDelegate{
    // 点击图片回调
    func cycleScrollView(_ cycleScrollView: SDCycleScrollView!, didSelectItemAt index: Int) {
        print("点击了第\(index + 1)张图片！")
    }
}
